#include <asm-generic/errno-base.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/sem.h>
union semun {
	int              val;    /* 信号量的值 */
	struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
	unsigned short  *array;  /* Array for GETALL, SETALL */
	struct seminfo  *__buf;  /* Buffer for IPC_INFO
								(Linux-specific) */
}; 

int main(int argc, char *argv[]) {
  key_t sem_key = ftok(".", 1);
  if (sem_key < 0) {
    perror("ftok fail");
    exit(-1);
  }

  int sem_id = semget(sem_key, 2, IPC_CREAT | IPC_EXCL | 0666);
  if (sem_id < 0) {
    if (errno == EEXIST) {
      sem_id = semget(sem_key, 2, 0666);
      if (sem_id < 0) {

        perror("semget fail");
        exit(-1);
      }
    } else {
      perror("semget fail");
      exit(-1);
    }
  }
  else if (sem_id > 0)
  {
    union semnum a;
    a.val = 1;

  }



  return 0;
}
